package com.chuangke.flow.controller;

import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.http.HttpResult;
import com.chuangke.flow.domain.MdFlowDeleteDto;
import com.chuangke.flow.entity.FlowMdFlow;
import com.chuangke.flow.service.FlowDefineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 【请填写功能名称】Controller
 * 
 * @author chuangke
 * @date "2020-09-27"
 */
@RestController
@RequestMapping("/flow/mdflow")
public class FlowDefineController {

	@Autowired
	private FlowDefineService flowDefineService;

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody FlowMdFlow flow) {
		return HttpResult.ok(flowDefineService.save(flow));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/page")
	public HttpResult page(@RequestBody Map<String, Object> pageQuery) {
		return HttpResult.ok(flowDefineService.page(new CkPageQuery(pageQuery)));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/delete")
	public HttpResult delete(@RequestBody MdFlowDeleteDto param) {
		flowDefineService.remove(param.getIds());
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping("/{id}")
	public HttpResult load(@PathVariable String id) {
		return HttpResult.ok(flowDefineService.load(id));
	}

}
